home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / bindings / fun / search-enter < prev    next >
Encoding:
Text File  |  1996-09-27  |  6.6 KB  |  200 lines

  1. @if-using not(ocl-file-search-enter)
  2.    @use (ocl-file-search-enter)
  3.    ;OCL{{{}}}
  4.    ;OCL{{{  reference description
  5.    @if-using ( FUN-REFERENCE ) ; 1 ;
  6.    This library defines a variant of enter fold, which tries to follow include
  7.    statements, if used on normal text.
  8.    @fi
  9.    ;OCL}}}
  10.    ;OCL{{{  libs
  11.    @use ( language-ocl )
  12.    @if-using not(ocl-file-userlang)  @lib userlang @fi
  13.    @if-using not(ocl-file-next-char) @lib next-char @fi
  14.    ;OCL}}}
  15.    ;OCL{{{  search-and-enter-fold
  16.    ;OCL{{{  reference
  17.    @if-using ( FUN-REFERENCE ) ; 2 ; search-and-enter-fold-called
  18.    ;OCL{{{  search-and-enter-fold
  19.    If used on a text-line, the command tries to follow a include statement on
  20.    that line. If this failes, the normal enter-fold action is activated (prompt
  21.    for filename). If the save of a chnaged file failes, the search for the
  22.    include file is omitted.
  23.  
  24.    @ref-start-tbl Language 8 Statement 32
  25.    all @@ #include "filename"
  26.    all @@ #include <filename>
  27.    OCL @@ @lib filename
  28.    OCL @@ @include filename
  29.    Roff @@ .so filename
  30.    @ref-end-tbl
  31.  
  32.    The files are searched in the `:'-separated directory-list, given by the
  33.    environement variable ORIGAMILIBPATH (default is `/usr/include').
  34.    ;OCL}}}
  35.    @fi
  36.    ;OCL}}}
  37.    ( history e-l-f-name )
  38.    ( history e-l-f-path )
  39.    ( defvar ( e-l-f-c e-l-f-x ) )
  40.    ( deffun search-and-enter-fold
  41.       ( set e-l-f-x store-pos
  42.         if
  43.          ;OCL{{{  line matches a iclude statement
  44.            and
  45.             ( test-text
  46.               not(in-prompt)
  47.               pre
  48.                ( if test-file-changed ( save-file ) fi )
  49.                  not(test-file-changed)
  50.               or
  51.                (
  52.                  ;OCL{{{  ocl:  @lib and @include
  53.                    and
  54.                     ( eval ( test-language-ocl )
  55.                       or
  56.                        ( test-str "@lib
  57.                          test-str "@include
  58.                          pre
  59.                           ( screen-off beginning-of-line screen-on )
  60.                             or
  61.                              ( test-str "@lib
  62.                                test-str "@include
  63.                              )
  64.                        )
  65.                     )
  66.                  ;OCL}}}
  67.                  ;OCL{{{  all:  #include
  68.                  and
  69.                   ( pre
  70.                      ( screen-off beginning-of-line screen-on )
  71.                        test-char "#
  72.                     pre
  73.                      ( screen-off next-non-space-on-line screen-on )
  74.                        test-str "include
  75.                   )
  76.                  ;OCL}}}
  77.                  ;OCL{{{  roff: #include
  78.                  and
  79.                   ( test-language Roff
  80.                     pre
  81.                      ( screen-off goto 1 screen-on )
  82.                        test-str ".so
  83.                   )
  84.                  ;OCL}}}
  85.                )
  86.             )
  87.          ;OCL}}}
  88.          ;OCL{{{  try to enter given file, return from macro on success
  89.          ( screen-off
  90.            ;OCL{{{  destination file into e-l-f-name
  91.            history-edit-line e-l-f-name ()
  92.               ;OCL{{{  skip command and limiting spaces
  93.               while not(test-char "  )
  94.                ( forward-character )
  95.               while and(test-char "  not(test-end-line))
  96.                ( forward-character )
  97.               ;OCL}}}
  98.               ;OCL{{{  delete in front of command
  99.               while not(test-begin-line)
  100.                ( delete-previous-character )
  101.               ;OCL}}}
  102.               ;OCL{{{  delete end of filename
  103.               case
  104.                ( test-char "" ( set e-l-f-c "" raw-delete-character ) )
  105.                ( test-char "< ( set e-l-f-c "> raw-delete-character ) )
  106.               default
  107.                ( set e-l-f-c "  )
  108.               esac
  109.               while and(not(test-char e-l-f-c ) not(test-end-line))
  110.                ( forward-character )
  111.               delete-to-end-of-line
  112.               ;OCL}}}
  113.               newline-and-indent
  114.            ;OCL}}}
  115.            ;OCL{{{  library path string to e-l-f-path
  116.            history-edit e-l-f-path ()
  117.               getenv "ORIGAMILIBPATH
  118.               if test-begin-line
  119.                ( "/usr/include:fun )
  120.               fi
  121.               newline-and-indent
  122.            ;OCL}}}
  123.            ;OCL{{{  enter the file, without any library path first
  124.            end-of-line
  125.            enter-fold
  126.               get-history e-l-f-name 0
  127.               newline-and-indent
  128.            ;OCL}}}
  129.            set e-l-f-x 0
  130.            do
  131.             ( case
  132.                ;OCL{{{  not line 1 or not bottom -> file found
  133.                ( or(not(test-bottom) >(store-line 1))
  134.                   ( change-buffername
  135.                        previous-line
  136.                        newline-and-indent
  137.                     beginning-of-fold
  138.                     next-line
  139.                     goto 1
  140.                     screen-on
  141.                     redraw-display
  142.                     return-from-macro
  143.                   )
  144.                )
  145.                ;OCL}}}
  146.                ;OCL{{{  e-l-f-x set -> last file tried -> break from loop
  147.                ( e-l-f-x ( set e-l-f-x 1 ) )
  148.                ;OCL}}}
  149.               default
  150.                ( insert-file
  151.                   ;OCL{{{  next-file-name
  152.                     ;OCL{{{  get path
  153.                     get-history e-l-f-path 0
  154.                     beginning-of-line
  155.                     while and(not(test-end-line) not(test-char ": ))
  156.                      ( forward-character )
  157.                     delete-to-end-of-line
  158.                     if not(test-begin-line) ( insert-ascii path-separator ) fi
  159.                     ;OCL}}}
  160.                     get-history e-l-f-name 0
  161.                     newline-and-indent
  162.                   ;OCL}}}
  163.                  set-file-unchanged
  164.                  ;OCL{{{  cut path element, maybe mark last try
  165.                  history-edit e-l-f-path ()
  166.                     previous-line
  167.                     beginning-of-line
  168.                     while and(not(test-char ": ) not(test-end-line))
  169.                      ( forward-character
  170.                        delete-previous-character
  171.                      )
  172.                     if not(test-end-line)
  173.                      ( forward-character
  174.                        delete-previous-character
  175.                      )
  176.                     fi
  177.                     if test-end-line
  178.                      ( set e-l-f-x -1 )
  179.                     fi
  180.                     newline-and-indent
  181.                  ;OCL}}}
  182.                )
  183.               esac
  184.             )
  185.            while <=(e-l-f-x 0)
  186.            exit-fold
  187.            screen-on
  188.            redraw-display
  189.          )
  190.          ;OCL}}}
  191.         fi
  192.         goto e-l-f-x
  193.         refresh-line
  194.         enter-fold
  195.       )
  196.    )
  197.    ( undeclare ( e-l-f-c e-l-f-x ) )
  198.    ;OCL}}}
  199. @fi
  200.